version 14
clear all
pause on
set more off

creturn list

global stata_code = "./stata_code"

*global stata_code = "C:\Users\alexander.smith\OneDriveWP\research\GitHub\eitc\taxtax"

do ${stata_code}/taxtax_define_specs.do   // This defines various elem ents of different specfications so they can be called easily below.
*global utility = "C:\Users\alexander.smith\OneDriveWP\research\utility"
*global results = "C:\Users\alexander.smith\OneDriveWP\research\projects\EITC\testing\"

global xs = "wagez3 "
global samps = "all k1elig" //elig noelig5
use  pik taxyr_out agecyr taxyr_cut pob wagez wagez3 using  ${clean_data}/taxtax_clean if inrange(taxyr_cut,1980,1981) ${sc_dropany_miss} & inrange(agecyr,19,37), clear

xtset pik taxyr_out

tempname memhold
tempfile rdest
postfile `memhold' str30(sample outcome) age corr mean using `rdest'

foreach samp of global samps {
  foreach x of global xs {
    gen F6`x'= f6.`x'
    forvalues a=19/36 {
      summ `x' if agecyr==`a' ${r_`samp'}
      local m = r(mean)
      local n = r(N)
      if `n'>0 & `n'!=. {
        if `a'<=30 {
          pwcorr `x' F6`x' if agecyr==`a' ${r_`samp'}
          local c = r(C)[2,1]
        }
        else local c = .

        post `memhold' (`"`samp'"') (`"`x'"') (`=`a'') (`=`c'') (`=`m'')
      }
    }
  }
}
postclose `memhold'

use `rdest', clear
save ${results}/wage_corrs_age, replace

local y = "wagez3"
graph twoway scatter corr age if  outcome=="`y'"  & sample=="all" & age<=30 , color(green) connect(l) ///
    || scatter corr age  if  outcome=="`y'" & sample=="k1elig" & age<=30 , color(orange) connect(l) ///
    xtitle("Age") xlabel(#6) ylabel(#4) yscale(range(0.3 0.8)) ytitle(Correlation (Age to Age+6)) ///
    legend( row(2) lab(1 "All") lab(2 "First-born EITC Eligible") )
graph export  ${results}/othergraphs/wage_corrs_age.pdf, replace
